import * as Cesium from "cesium"
import AmapImageryProvider from './imagery/amap/AmapImageryProvider'
import BaiduImageryProvider from './imagery/baidu/BaiduImageryProvider'
import TencentImageryProvider from './imagery/tencent/TencentImageryProvider'
import TdtImageryProvider from './imagery/tdt/TdtImageryProvider'
import GoogleImageryProvider from './imagery/google/GoogleImageryProvider'

/**
 * 影像相关工具类
 */
export class ImageryUtils {
    constructor(private viewer: Cesium.Viewer) {

    }
    /**
     * 设置底图透明度
     * @param opacity 透明度
     */
    setBaseLayerOpacity(opacity: number) {
        if(opacity === 0) {
            (this.viewer.imageryLayers as any)._layers[0].show = false;
        }else{
            (this.viewer.imageryLayers as any)._layers[0].show = true;
            (this.viewer.imageryLayers as any)._layers[0].alpha = opacity;
        }
    }
    /**
     * 获取天地图电子地图provider
     * @returns 
     */
    getTianDiTuElectroncisImageryProvider() {
        return new Cesium.WebMapTileServiceImageryProvider({
            url: "http://{s}.tianditu.gov.cn/vec_c/wmts?service=wmts&request=GetTile&version=1.0.0" +
                "&LAYER=vec&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}" +
                "&style=default&format=tiles&tk=00539456b0b4a9228b436dcb209be82d",
            layer: "tdtCva",
            style: "default",
            format: "tiles",
            tileMatrixSetID: "c",
            subdomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
            tilingScheme: new Cesium.GeographicTilingScheme(),
            tileMatrixLabels: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"],
            maximumLevel: 18,
        })

    }
    /**
     * 获取天地图路线地图provider
     */
    getTianDiTuBiaoJiImageryProvider() {
        return new Cesium.WebMapTileServiceImageryProvider({
            url: "http://{s}.tianditu.gov.cn/cia_c/wmts?service=wmts&request=GetTile&version=1.0.0" +
                "&LAYER=cia&tileMatrixSet=c&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}" +
                "&style=default&format=tiles&tk=00539456b0b4a9228b436dcb209be82d",
            layer: "tdtCva",
            style: "default",
            format: "tiles",
            tileMatrixSetID: "c",
            subdomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
            tilingScheme: new Cesium.GeographicTilingScheme(),
            tileMatrixLabels: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19"],
            maximumLevel: 18,
        })
    }
    /**
     * 获取ArcGis影像地图provider
     * @returns 
     */
    getArcGisImageryImageryProvider() {
        return new Cesium.ArcGisMapServerImageryProvider({
            url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer",
        })
    }
    /**
     * 获取高德影像地图provider（可解决底图坐标系问题）
     * @example
     * var options = {
            style: 'img', // style: img、elec、cva
            crs: 'WGS84' // 使用84坐标系，默认为：GCJ02
        }
        viewer.imageryLayers.addImageryProvider(jesium.imageryUtils.getAmapImageryProvider(options))
     */
    getAmapImageryProvider(option: {
        style: string,
        crs: string
    }) {
        return new AmapImageryProvider(option);
    }
    /**
     * 获取百度地图provider（可解决底图坐标系问题）
     * @example 
     * var options = {
            style: 'normal', // style: img、vec、normal、dark
            crs: 'WGS84' // 使用84坐标系，默认为：BD09
        }
        viewer.imageryLayers.addImageryProvider(jesium.imageryUtils.getBaiduImageryProvider(options))
     * @returns 
     */
    getBaiduImageryProvider(option: {
        style: string,
        crs: string
    }) {
        return new BaiduImageryProvider(option) as any;
    }
    /**
     * 获取腾讯地图provider
     * @example
     * var options = {
            style: 1 //style: img、1：经典
        }

        viewer.imageryLayers.addImageryProvider(jesium.imageryUtils.getTencentImageryProvider(options))
     * @returns 
     */
    getTencentImageryProvider(option: {
        style: string,
    }) {
        return new TencentImageryProvider(option);
    }
    /**
     * 获取天地图provider
     * @example
     * var options = {
            style: 'vec', //style: vec、cva、img、cia、ter 
            key: '' // token
        }
        viewer.imageryLayers.addImageryProvider(jesium.imageryUtils.getTdtImageryProvider(options))
     */
    getTdtImageryProvider(option: {
        style: string,
        key: string
    }) {
        return new TdtImageryProvider(option);
    }
}